﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace FileStreamsAndCrypto
{
    class CryptSha1
    {
        public static string GenerateHash(string filePathAndName)
        {
            string hashText = "";
            string hexValue = "";

            //byte[] fileData = File.ReadAllBytes(filePathAndName);
            FileStream fs = new FileStream(filePathAndName, FileMode.Open);
            using (fs)
            {
                byte[] hashData = SHA1.Create().ComputeHash(fs); // SHA1 or MD5

                foreach (byte b in hashData)
                {
                    hexValue = b.ToString("X").ToLower(); // Lowercase for compatibility on case-sensitive systems
                    hashText += (hexValue.Length == 1 ? "0" : "") + hexValue;
                }
            }
            return hashText;
        }

        //static void Main()
        //{
        //    string hashstring = GenerateHash(@"C:\Users\Academy\Desktop\New Text Document(2).txt");
        //    string test = "1a0b0ee5b1909d2dc42d825ff6a947465d0a083f";
        //    Console.WriteLine(hashstring);
        //    Console.WriteLine(test);
        //}
    }
}
